Page 88 - 2629_Devagiri_C-8
P. 88

BRIDGE BACK
                   1.  What is the full form of IDLE?

                   2.  What is the use of the % operator?
                   3.  Fill in the correct operator.

                      (a)  6             3 = 18?
                      (b)  8             4 + 4 = 6?





                  In the previous class, you learnt that Python is a high-level, interpreted programming language
                  known for its simplicity and readability. You also explored how to download and install it on your
                  system and wrote and executed simple short programs in Python. In this chapter, you are going
                  to move onwards with Python basics and write more advanced programs.




                         PYTHON ITERATIVE STATEMENTS


                  Iteration means repeating a set of instructions again and again. It is a flow of control that allows
                  a part of the code to run multiple times without writing it again each time. In many programs, we
                  often need to repeat certain actions. Instead of copying the same code many times, we use loops
                  to do it automatically.

                  Using loops helps save time, reduce mistakes and make the code shorter and cleaner.
                  Python provides two main types of loops: the for loop, which repeats a block of code for each item
                  in a sequence or for a specific number of iterations and the while loop, which repeats a block of
                  code as long as a condition is true.

                  range() function
                  The range() function is a built-in function in Python that generates a sequence of numbers.

                  The range() function is most commonly used
                  with the  for loop  to  repeat  tasks  a specific
                  number of times.
                                                                      Python has no limit on variable name length, but
                  Syntax of the range() function:                     line lengths should be kept under 79 characters


                  range(start, stop, step)                            for better readability.
                  where,
                      start: This is the optional value where the sequence begins. If you don’t specify it, Python will
                     automatically start from 0.

                     For example, range(5) is treated as range(0, 5) and generates: [0, 1, 2, 3, 4].

                      stop: This is the mandatory value at which the sequence ends, but it is not included in the
                     result.




                   86
                        Premium Edition-VIII
   83   84   85   86   87   88   89   90   91   92   93